import Taro from '@tarojs/taro'
const baseurl = 'http://127.0.0.1:8092';  // 正试环境 13500580945
// const baseurl = 'http://192.168.2.85:8092';  // 正试环境 13500580945
const IMGAGE = 'http://qls72aowd.hn-bkt.clouddn.com';  // 正试环境 13500580945
// const baseurl = 'http://81.68.130.44:8092';  // 正试环境
// http://81.68.130.44:8080/
async function HTTP(url, data, method) {
    let header = {}
    if (method === 'POST') {
        header = {
            "Content-Type": "application/x-www-form-urlencoded",
        }
    } else {
        header = {
            "content-type": "application/json",
        }
    }
    if (url.indexOf('/tour/auth/smclogin') === -1 && url.indexOf('/tour/auth/getPhoneCode') === -1) {
        header['Authorization-Token'] = Taro.getStorageSync('userInfo').token
    }
    return new Promise((resolve, reject) => {
        Taro.request({
            url: baseurl + url,
            data: data,
            header: header,
            method: method,
            success: function (res) {
                //如果没有登录的操作
                resolve(res.data) //把请求到的数据发到引用请求的地方
            },
            fail: function (err) {
                reject(err)
                Taro.showToast({
                    title: '网络连接超时',
                    icon: 'none',
                    duration: 3000
                })
            }
        })
    }).catch(res => {
        console.log(res)
    })
}
export { HTTP, baseurl, IMGAGE }